home *** CD-ROM | disk | FTP | other *** search
/ Racing Games (Spidla) / zavodni.iso / Fun Racing / src / FRGameLogo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-06-19  |  4.7 KB  |  223 lines

  1.  
  2.  
  3. #include "FRGameLogo.h"
  4.  
  5. #include "FRCop.h"
  6. #include "FRAmbulance.h"
  7. #include "FRGolf.h"
  8. #include "FRFuneralCar.h"
  9.  
  10. TERTTIImplementation(FRCloakLogo, TEEngineObject);
  11. TERTTIImplementation(FRLoserGolf, FRCar);
  12.  
  13. TESoundReference* FRGameLogo::ms_pTechno = NULL;
  14. TESoundReference* FRGameLogo::ms_pCrash = NULL;
  15. UInt32 FRGameLogo::ms_ulLogoStart = 0;
  16. UInt32 FRGameLogo::ms_ulLogoState = 0;
  17.  
  18. void FRGameLogo::Start(void)
  19. {
  20.     Initialize();
  21.     Loop();
  22.     Cleanup();
  23. }
  24.  
  25. void FRGameLogo::Initialize(void)
  26. {
  27.     TEString Str = "techno.ogg";
  28.     TESoundManager* pSound = TESoundManager::GetSoundManager();
  29.  
  30.     ms_pTechno = pSound->GetSound(Str);
  31.     Str = "crash.ogg";
  32.     ms_pCrash = pSound->GetSound(Str);
  33.  
  34.     Str = "load funracing-logo.bsp";
  35.     TEConsole::GetConsole()->EnterCommand(Str, true);
  36.  
  37.     ms_ulLogoState = 1;
  38.     ms_ulLogoStart = TETimer::GetTimer()->GetTime();
  39. }
  40.  
  41. void FRGameLogo::Cleanup(void)
  42. {
  43.     TEString Str = "unload";
  44.  
  45.     TEConsole::GetConsole()->EnterCommand(Str, true);
  46.  
  47.     SafeDelete(ms_pTechno);
  48.     SafeDelete(ms_pCrash);
  49.     ms_ulLogoState = 0;
  50.     ms_ulLogoStart = 0;
  51. }
  52.  
  53. void FRGameLogo::Loop(void)
  54. {
  55.     TEEngine* pEngine = TEEngine::GetEngine();
  56.     TERenderer* pRender = TERenderer::GetRenderer();
  57.     TECamera* pCam = pRender->GetCamera();
  58.     TEInputDevices* pInput = TEInputDevices::GetInputDevices();
  59.     TETimer* pTimer = TETimer::GetTimer();
  60.     UInt32 ulTime = pTimer->GetTime() - ms_ulLogoStart;
  61.     TEVector Vec, Up = TEVector(0, 1, 0);
  62.     TEParticleFX* pPart;
  63.     FRLoserGolf* pGolf;
  64.     FRCar *pAmb, *pFun;
  65.     FRCloakLogo* pLogo;
  66.  
  67.     pEngine->ShowCursor(false);
  68.     Vec = TEVector(85, 50, -85);
  69.     pCam->SetPosition(Vec);
  70.     Vec = TEVector(-20, 42, 0);
  71.     pCam->SetRotation(Vec);
  72.  
  73.     Vec = TEVector(160.0f, 5.0f, 47.5f);
  74.     pGolf = new FRLoserGolf(Vec, 270);
  75.     pGolf->m_State = RACING;
  76.     pGolf->SetPedal(1.0f);
  77.  
  78.     pEngine->AddObjectToWorld(pGolf);
  79.  
  80.     ms_pTechno->Play3D(Vec.m_fX, Vec.m_fY, Vec.m_fZ, 0);
  81.  
  82.     while(ulTime < 18500)
  83.     {
  84.         pEngine->Idle();
  85.  
  86.         if(ms_ulLogoState == 1)
  87.         {
  88.             Vec = pGolf->GetCenter();
  89.             ms_pTechno->UpdatePosition(Vec);
  90.  
  91.             if(Vec.m_fX < 30.0f)
  92.             {
  93.                 ms_ulLogoState = 2;
  94.                 pGolf->Brake();
  95.             }
  96.         }
  97.         
  98.         if(ms_ulLogoState == 2)
  99.         {
  100.             Vec = pGolf->GetCenter();
  101.  
  102.             if(Vec.m_fX < -62.0f)
  103.             {
  104.                 ms_ulLogoState = 3;
  105.                 pGolf->Stop();
  106.                 pGolf->m_State = DESTROYED;
  107.                 ms_pCrash->Play(0, 4.0f);
  108.                 
  109.                 Vec.m_fX -= 4.0f;
  110.                 Vec.m_fY += 6.0f;
  111.                 pPart = new TEParticleFX(Vec, 2, 4, 2.0f, 0, 0, 0, Up, 200, 1300,
  112.                     255, 1.0f, true, false);
  113.                 pPart->SetColor(255, 128, 64);
  114.                 pEngine->AddParticleSystem(pPart);
  115.             }
  116.         }
  117.         
  118.         if(ms_ulLogoState == 3 && ulTime > 6300)
  119.         {
  120.             Vec = TEVector(160.0f, 5.0f, 47.5f);
  121.             pAmb = new FRAmbulance(Vec, 270);
  122.             pAmb->m_State = RACING;
  123.             pAmb->Horn();
  124.             pAmb->SetPedal(0.5f);
  125.             pEngine->AddObjectToWorld(pAmb);
  126.             ms_ulLogoState = 4;
  127.         }
  128.         if(ms_ulLogoState == 4)
  129.         {
  130.             Vec = pAmb->GetCenter();
  131.  
  132.             if(Vec.m_fX < 45.0f)
  133.             {
  134.                 pAmb->SetPedal(0.0f);
  135.                 pAmb->SetHandbrake(true);
  136.                 ms_ulLogoState = 5;
  137.             }
  138.         }
  139.         if(ms_ulLogoState == 5)
  140.         {
  141.             Vec = pAmb->GetCenter();
  142.  
  143.             if(Vec.m_fX < 30.0f || pAmb->GetGear() < FIRST_GEAR)
  144.             {
  145.                 pAmb->Horn();
  146.                 pAmb->m_State = DESTROYED;
  147.                 Vec = TEVector(0,0,0);
  148.                 pAmb->SetAcceleration(Vec);
  149.                 pAmb->SetVelocity(Vec);
  150.                 ms_ulLogoState = 6;
  151.             }
  152.         }
  153.  
  154.         if(ms_ulLogoState > 5)
  155.         {
  156.             Vec = TEVector(0,0,0);
  157.             pAmb->SetAcceleration(Vec);
  158.             pAmb->SetVelocity(Vec);
  159.         }
  160.  
  161.         if(ms_ulLogoState == 6)
  162.         {
  163.             Vec = TEVector(-47.5f, 5.0f, -175.0f);
  164.             pFun = new FRFuneralCar(Vec, 0);
  165.             pFun->m_State = RACING;
  166.             pFun->SetPedal(1.0f);
  167.             pEngine->AddObjectToWorld(pFun);
  168.             ms_ulLogoState = 7;
  169.         }
  170.  
  171.         if(ms_ulLogoState == 7)
  172.         {
  173.             Vec = pFun->GetCenter();
  174.  
  175.             if(Vec.m_fZ > -50.0f)
  176.             {
  177.                 pFun->SetPedal(-0.5f);
  178.                 pFun->SetHandbrake(true);
  179.                 ms_ulLogoState = 8;
  180.             }
  181.         }
  182.  
  183.         if(ms_ulLogoState == 8)
  184.         {
  185.             Vec = pFun->GetCenter();
  186.  
  187.             if(Vec.m_fZ > -45.0f || pFun->GetGear() < FIRST_GEAR)
  188.             {
  189.                 pFun->SetPedal(0.0f);
  190.                 Vec = TEVector(0,0,0);
  191.                 pFun->SetAcceleration(Vec);
  192.                 pFun->SetVelocity(Vec);
  193.                 pFun->m_State = DESTROYED;
  194.                 ms_ulLogoState = 9;
  195.             }
  196.         }
  197.  
  198.         if(ms_ulLogoState > 8)
  199.         {
  200.             Vec = TEVector(0,0,0);
  201.             pFun->SetAcceleration(Vec);
  202.             pFun->SetVelocity(Vec);
  203.         }
  204.  
  205.         if(ms_ulLogoState == 9 && ulTime > 13000)
  206.         {
  207.             pLogo = new FRCloakLogo;
  208.             pEngine->AddObjectToWorld(pLogo);
  209.             ms_ulLogoState = 10;
  210.         }
  211.  
  212.         ulTime = pTimer->GetTime() - ms_ulLogoStart;
  213.  
  214.         if(pInput->IsPressed(TE_KEY_ESCAPE) || 
  215.             pInput->IsPressed(TE_KEY_ENTER) || 
  216.             pInput->IsPressed(TE_KEY_SPACE))
  217.             break;
  218.     }
  219.  
  220.     pEngine->FreeAllDecals();
  221.     pEngine->FreeAllObjectsInWorld();
  222.     pEngine->FreeAllParticleSystems();
  223. }